﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 接口
{
    internal class Program
    {
        static void Main(string[] args)
        {
            int[] num =  { 1, 2, 3, 4, 5, 8, 9, 10, 11, 12};
            Console.WriteLine(Sum(num));
            Console.WriteLine(Avg(num));

            ArrayList list = new ArrayList { 1, 2, 3, 4, 5, 8, 9, 10, 11, 12 };
            
            Console.WriteLine(Program2.Sum(list));
            Console.WriteLine(Program2.Avg(list));
            Console.WriteLine(Program2.Sum(num));
            Console.WriteLine(Program2.Avg(num));
            
            Console.ReadKey();
        }

        static int Sum(int[] nums)
        {
            int sum = 0;
            foreach (int x in nums)
            {
                sum += x;
            }
            return sum;
        }

        static double Avg(int[] nums)
        {
            int sum = 0;
            double count = 0;
            foreach(int x in nums)
            {
                sum += x;
                count++;
            }
            return sum / count;
        }
    }


    internal class Program2
    {
        public static int Sum(IEnumerable nums)
        {
            int sum = 0;
            foreach (var x in nums)
            {
                sum += (int)x;
            }
            return sum;
        }

        public static double Avg(IEnumerable nums)
        {
            int sum = 0;
            double count = 0;

            foreach (var x in nums)
            {
                sum += (int)x;
                count++;
            }
            return sum / count;
        }
    }


    // 接口
    // 接口即契约，约束服务的提供者，也约束服务的使用者
    // 都是虚方法，没有实现
    // 所有方法都时public
    interface IClass
    {

    }



}
